<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>员工信息管理系统 - 仪表盘</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
    <div class="logo">员工信息管理系统</div>
    <div class="user-info">
        <span>欢迎, <%= ((com.cmq.web_1.employeemanage.User) session.getAttribute("user")).getUsername() %></span>
        <a href="logout" class="logout-btn">退出登录</a>
    </div>
</header>

<nav>
    <ul>
        <li><a href="dashboard" class="active">仪表盘</a></li>
        <li><a href="employeemanage/list">员工管理</a></li>
    </ul>
</nav>

<main>
    <div class="dashboard-stats">
        <div class="stat-card">
            <h3>员工总数</h3>
            <p><%= ((java.util.List) request.getAttribute("employees")).size() %></p>
        </div>
        <div class="stat-card">
            <h3>部门数量</h3>
            <p>
                <%
                    java.util.Set<String> departments = new java.util.HashSet<>();
                    for (Object emp : (java.util.List) request.getAttribute("employees")) {
                        departments.add(((com.cmq.web_1.employeemanage.Employee) emp).getDepartment());
                    }
                    out.print(departments.size());
                %>
            </p>
        </div>
    </div>

    <!-- 最近员工列表 -->
    <div class="recent-employees">
        <h2>最近员工</h2>
        <a href="employeemanage/add" class="btn add-btn">添加员工</a>

        <table>
            <thead>
            <tr>
                <th>ID</th>
                <th>姓名</th>
                <th>部门</th>
                <th>职位</th>
                <th>入职日期</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <%
                // 显示最近5名员工
                java.util.List<com.cmq.web_1.employeemanage.Employee> employees =
                        (java.util.List<com.cmq.web_1.employeemanage.Employee>) request.getAttribute("employees");
                int count = 0;
                for (com.cmq.web_1.employeemanage.Employee emp : employees) {
                    if (count >= 5) break;
            %>
            <tr>
                <td><%= emp.getId() %></td>
                <td><%= emp.getName() %></td>
                <td><%= emp.getDepartment() %></td>
                <td><%= emp.getPosition() %></td>
                <td><%= new java.text.SimpleDateFormat("yyyy-MM-dd").format(emp.getHireDate()) %></td>
                <td>
                    <a href="employeemanage/view?id=<%= emp.getId() %>" class="action-btn view">查看</a>
                    <a href="employeemanage/edit?id=<%= emp.getId() %>" class="action-btn edit">编辑</a>
                    <a href="employeemanage/delete?id=<%= emp.getId() %>" class="action-btn delete"
                       onclick="return confirm('确定要删除该员工吗？')">删除</a>
                </td>
            </tr>
            <%
                    count++;
                }
            %>
            </tbody>
        </table>
    </div>
</main>

<footer>
    <p>&copy; 2023 员工信息管理系统 版权所有</p>
</footer>
</body>
</html>